package uk.org.landeg.euler.problems;

import java.util.TreeSet;

import uk.org.landeg.euler.problems.framework.AbstractProblem;
import uk.org.landeg.euler.problems.framework.ProblemLauncher;
import uk.org.landeg.euler.problems.lib.NumbersLib;

public class Problem023 extends AbstractProblem {
	public static void main(String[] args) {
		ProblemLauncher launcher = new ProblemLauncher(new Problem023());
		launcher.solve();		
	}
	
	@Override
	public String getDescription() {
		// TODO Auto-generated method stub
		return "Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.";
	}

	@Override
	public Integer getProblemNumber() {
		// TODO Auto-generated method stub
		return 23;
	}

	TreeSet<Integer> abundantNumbers = new TreeSet<Integer>();
	@Override
	public Object solve() {
		notes.add("Find all abundant numbers below 28123");
		notes.add("it is know that the maximum number that cannot be expressed as the sum to two abundant numbers is less than this value");
		notes.add("Finding abundant numbers;");
		System.out.println(NumbersLib.getDivisors(12));
		for (int n = 1 ; n < 28123 ; n++) {
			if (NumbersLib.sum(NumbersLib.getDivisors(n)) > n) {
				abundantNumbers.add(n);
			}
		}
		long total = 0;
		notes.add("Found " + abundantNumbers.size() + " abundants");
		boolean notSum;
		for (int n = 1; n < 28123 ; n++) {
			notSum = true;
			for (int ab1 : abundantNumbers) {
				if (ab1 >= n) {
					break;
				}
				if (abundantNumbers.contains(n-ab1)) {
					notSum = false;
					break;
				}
			}
			if (notSum) {
				total += n;
			}
		}
		return total;
	}

}
